package com.example.trafficsystem.controller;

import com.example.trafficsystem.entity.Task;
import com.example.trafficsystem.service.OssService;
import com.example.trafficsystem.service.TaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/trainingDocument")
@CrossOrigin // 允许跨域
public class TaskController {
    @Autowired
    private TaskService taskService;
    @Autowired
    private OssService ossService;

    @GetMapping("/{taskId}")
    public Task getTrainingDocument(@PathVariable Long taskId) {
        Task task = taskService.findDocumentById(taskId);
           if (task != null&&task.getDocumentUrl()!=null){
               String url = ossService.getUrl(task.getDocumentUrl());
                task.setDocumentUrl(url);
           }
        return task;
    }

}
